<?php
namespace jy_wxshifu;
defined('BY_JYA') or exit('error');
/*
	插件工具类
*/
class model extends \plugin{
	public function addorder($order=array(),$status=0,$plugin=''){
		$isaddid=pdo_getcolumn('jy_wxshifu_order',array('orderid'=>$order['id'],'uniacid'=>$_SESSION['uniacid'],'plugin'=>$plugin),'id');
		if($isaddid){
			return $isaddid;
		}
		$data=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$order['mid'],
				'orderid'=>$order['id'],
				'ordersn'=>$order['ordersn'],
				'price'=>$order['price'],
				'sendtype'=>$order['sendtype'],
				'plugin'=>$plugin,
				'status'=>$status,
				'createtime'=>TIMESTAMP,
		);
		$this->insert('order',$data);
		return $this->insertid();
	}
	public function getshifu($order=array(),$plugin=''){
		$shifu_order=pdo_get('jy_wxshifu_order',array('orderid'=>$order['id'],'uniacid'=>$_SESSION['uniacid'],'plugin'=>$plugin));
		if($shifu_order['shifuid']){
			$shifuinfo=pdo_get('jy_wxshifu_member',array('id'=>$shifu_order['shifuid'],'uniacid'=>$_SESSION['uniacid']),array('title','mobile'));
		}
		if($shifu_order['status']==5){
			$shifuinfo['baobeimsg']=pdo_getcolumn('jy_wxshifu_baobei_log',array('uniacid'=>$_SESSION['uniacid'],'order_id'=>$shifu_order['id']),'msg');
		}
		return $shifuinfo;
	}
	public function getorder($order=array(),$isinfo=0){
		if(!$order['plugin']){
			return false;
		}
		$order=model($order['plugin'].'/model')->getorder($order,$isinfo);
		return $order;
	}
	public function uporder($order=array(),$status=0,$shifuid=0,$remark='',$price=0){
		$update=array('status'=>$status,'images'=>ijson_encode($order['images']),'upfile'=>$order['upfile']);
		if($shifuid){
			$update['shifuid']=$shifuid;
		}
		if($remark){
			$update['remark']=$remark;
		}
		if($price){
			$update['price']=$price;
		}
		pdo_update('jy_wxshifu_order',$update,array('id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']));
		if(!$order['plugin']){
			return false;
		}
		model($order['plugin'].'/model')->uporder($order,$status,$shifuid,$remark,$price);
		return true;
	}
	public function order_receive($order=array(),$plugin=''){
		$order_id=pdo_getcolumn('jy_wxshifu_order',array('orderid'=>$order['id'],'uniacid'=>$_SESSION['uniacid'],'plugin'=>$plugin),'id');
		$this->model('order')->create_orderlog($order_id);
		$order=pdo_get('jy_wxshifu_order',array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		$this->model('order')->up_sendlog($order_id,'',2);
		return true;
	}
}